<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * create html-code for pagination of
 * category browse page
 * used from category.page.table.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2015
 * @author     Norbert Gebert
 * @license    GPL3
 */
/*
 * @param object	$refPage		reference to page-class
 * @param int		$number		number of category-entrys
 * @ return string html-Code for output
 */

function getPagination($refPage, $number)
{
	$lastPage = ceil($number / CATEGORY_LIST);

	$refPage->assign('urlPageFirst', 'index2.php?page=article&sub=category&func=pagi&nr=1');
	$refPage->assign('txtPageFirst', _('&lt;&lt; First'));

	if ($_SESSION['pageC'] == 1)
	{
		$refPage->assign('urlPagePrev',
			'index2.php?page=article&sub=category&func=pagi&nr=' . 1);
	}
	else
	{
		$refPage->assign('urlPagePrev',
			'index2.php?page=article&sub=category&func=pagi&nr=' . ($_SESSION['pageC'] - 1));
	}
	
	$refPage->assign('txtPagePrev', _('&lt; Back'));

	if ($_SESSION['pageC'] == $lastPage)
	{
		$refPage->assign('urlPageNext',
			'index2.php?page=article&sub=category&func=pagi&nr=' . $lastPage);
	}
	else
	{
		$refPage->assign('urlPageNext',
			'index2.php?page=article&sub=category&func=pagi&nr=' . ($_SESSION['pageC'] + 1));
	}

	$refPage->assign('txtPageNext', _('Next &gt;'));
	$refPage->assign('urlPageLast',
		'index2.php?page=article&sub=category&func=pagi&nr=' . $lastPage);
	$refPage->assign('txtPageLast', _('Last &gt;&gt;'));

	$display = ceil(ARTICLE_PAGES / 2);
	$urlPageP = array();
	$urlPageN = array();

	if ($_SESSION['pageC'] > 1)
	{
		$start = $_SESSION['pageC'] - $display;
		$ende = $_SESSION['pageC'] - 1;

		for ($value = $start; $value <= $ende; $value++)
		{
			if ($value <= 0)
				continue;

			$urlPageP[] = array(
			 'url' => 'index2.php?page=article&sub=category&func=pagi&nr=' . $value,
			 'text' => $value);
		}
	}
	$refPage->assign('urlPageP', $urlPageP);
	$refPage->assign('nrPageC', $_SESSION['pageC']);

	if ($_SESSION['pageC'] < $lastPage)
	{
		$start = $_SESSION['pageC'] + 1;
		$ende = $_SESSION['pageC'] + $display;

		for ($value = $start; $value <= $ende; $value++)
		{
			if ($value >= $lastPage + 1)
				continue;

			$urlPageN[] = array(
			 'url' => 'index2.php?page=article&sub=category&func=pagi&nr=' . $value,
			 'text' => $value);
		}
	}

	$refPage->assign('PageN', $urlPageN);
}

?>